package com.lft.juc03.lock8;

import java.util.concurrent.TimeUnit;

/**
 * 线程8锁——锁8.
 * 两个静态同步方法，两个对象
 * 静态同步方法的调用者是Class，Class是唯一。即使是两个对象，但是锁是同一个Class需要挣抢锁。
 */
public class Lock8 {
	public static void main(String[] args) {
		Phone8 phone1 = new Phone8();
		Phone8 phone2 = new Phone8();
		new Thread(() -> {phone1.senSms();}, "A").start();
		try {TimeUnit.SECONDS.sleep(2);} catch (InterruptedException e) {e.printStackTrace();}
		new Thread(() -> {phone2.call();}, "B").start();
	}
}

class Phone8 {
	public static synchronized void senSms() {
		// 新增Thread.sleep()给 senSms()
		try {TimeUnit.SECONDS.sleep(4);} catch (InterruptedException e) {e.printStackTrace();}
		System.out.println(Thread.currentThread().getName() + " 发短信");
	}
	
	public static synchronized void call() {
		System.out.println(Thread.currentThread().getName() + " 打电话");
	}
}